<script src="__PUBLIC__/js/artDialog/jquery.artDialog.js?skin=default"></script>
<script src="__PUBLIC__/js/artDialog/plugins/iframeTools.js"></script>
<style type="text/css">
a.a_upload,a.a_choose{
	border:1px solid #3d810c;
	box-shadow:0 1px #cccccc;
	-moz-box-shadow:0 1px #cccccc;
	-webkit-box-shadow:0 1px #cccccc;
	cursor:pointer; 
	display: inline-block;
	text-align: center;
	vertical-align:bottom;
	overflow:visible;
	border-radius:3px;
	-moz-border-radius:3px;
	-webkit-border-radius:3px;
	vertical-align:middle;
	background-color: #f1f1f1;
	background-image: -webkit-linear-gradient(bottom, #ccc 0%, #e5e5e5 3%, #fff 97%, #fff 100%);
	background-image: -moz-linear-gradient(bottom, #ccc 0%, #e5e5e5 3%, #fff 97%, #fff 100%);
	background-image: -ms-linear-gradient(bottom, #ccc 0%, #e5e5e5 3%, #fff 97%, #fff 100%);
	color: #000;
	border:1px solid #aaa;
	padding:2px 8px 2px 8px;
	text-shadow: 0 1px #ffffff;
	font-size: 14px;
	line-height: 1.5;
}

.cmbitem {
	width: 100px;
	text-align: center;
}
.optsitem {
	float: right;
	margin-right: 50px;
}
.poptvalue {
	width:20px;
	text-align:center;
}
</style>
<div class="pd-20">
    <form action="" method="post" class="form form-horizontal" action="{:U("Admin/Order/editAutoOrder")}"  onsubmit="return checkForm()">
    	<!-- 订单id -->
    	<input type="hidden" name="orderid" value="{$orderid}">
    	<!-- 期数id -->
    	<input type="hidden" name="pid" value="{$curItem['periodid']}">
    	<!-- 期数名称 -->
    	<input type="hidden" value="{$curItem['pname']}" id="curPid" name="curPname">
    	<div class="row cl">
        	<label class="form-label col-3"><span class="c-red"></span>套餐期数</label>
            <div class="col-6">
	            <input type="text" class="input-text" value="{$curItem['pname']}" placeholder="" id="curCPid" name="curCPid" datatype="*2-16" nullmsg="" disabled="disabled">
	            
            </div>
            <div class="col-3"></div>
        </div>
        <div class="row cl">
        	<label class="form-label col-3"><span class="c-red"></span>搭配号</label>
            <div class="col-6">
	            <input type="text" class="input-text" value="{$colname}" placeholder="" id="colname" name="colname" datatype="*2-16" nullmsg="" disabled="disabled">
            </div>
            <div class="col-3"></div>
        </div>
        <div class="row cl">
        	<label class="form-label col-3"><span class="c-red"></span>选择菜品</label>
            <div class="col-6">
	            <ul id='foods'>
	            <volist name="cbpFoods" id="food" key="k">
	            	<li class="fooditem">
	            		<span class="cbmitem">
	            			<input class="cbmitem-input" type="checkbox" name="foods[{$food.foodid}]" value="{$food.foodid}" data="{$food.foodid}">{$food.foodname}:
	            		</span>
	            		<input type="hidden" class="foodischs" name="foods[{$food.foodid}][isChs]" <if condition="$orderFoods['colfood'][$food['foodid']]['num'] egt 1">value="1"<else/>value="0"</if>>
	            		<span class="optsitem" name="{$food.foodname}-opt">
	            			<label class="poptitem">分值<input type="text" name="foods[{$food.foodid}][cicredit]" value="{$food.credit}" class="poptvalue foodcredit" disabled="disabled"></label>
	            			<label class="poptitem">份数<input type="text" name="foods[{$food.foodid}][num]" value="1" class="poptvalue foodcount"></label>
	            		</span>
	            		<input type="hidden" class="foodname" name="foods[{$food.foodid}][name]" value="{$food.foodname}">
	            		<input type="hidden" class="foodname" name="foods[{$food.foodid}][ftype]" value="colfood">
	            	</li>
	            </volist>
	            </ul>
            </div>
            <div class="col-3"></div>
        </div>
        <div class="row cl">
        	<label class="form-label col-3"><span class="c-red"></span>套餐分值</label>
            <div class="col-6">
	            <input type="text" class="input-text" value="{$colCreditTotal}" placeholder="" id="tCredit" name="tCredit" datatype="*2-16" nullmsg="" disabled="disabled">
            </div>
            <div class="col-3"></div>
        </div>
        <div class="row cl">
            <div class="col-9 col-offset-3">
                <input name="fomr-add" class="btn btn-success " type="submit" value="&nbsp;提交&nbsp;">
            </div>
        </div>
    </form>
</div>
<script>
// 适配3.2
var site_url = '{:U("Admin/Upyun/upload", array(), false)}';
var foodCreditTotal = {$colCreditTotal};
//用户-编辑
function manage_edit(title, url, id, w, h, pc) {
	var height = 440 + (h-1)*31;
	if(pc == null) {
		height -= 31;
	}
    layer_show(title, url, w, height);
}
function changesort(obj) {
	//window.location.href="/index.php?g=Admin&m=Order&a=showAll&state="+$(obj).val();
	var sortid = $(obj).val();
	$('#sid').val(sortid);
}
function changeCbpName(obj) {
	var cbpid = $(obj).val();
	$('#cpname').val(cbpid);
	var sel = $('#collocations-sel');
	// 清除sel中的选项
	sel.empty();
	
	$.ajax({
		url: '{:U("Admin/Order/getOneCollocations")}',
		type: 'POST',
		asyn:true,
		data:{
			combopackid:cbpid
		},
		timeout: 10000,
		dataType:'json',
		success:function(data, textStatus, jsqXHR) {
			console.log('data=>'+data);
			var collocations = eval(data);
			console.log('data0 =>' + collocations[0]);
			for(var i=0;i<collocations.length;i++) {
				sel.append('<option value="'+collocations[i]+'">'+collocations[i]+'</option>');
			}
			$('#colname').val(collocations[0]);
			
		},
		error:function(data, textStatus) {
			alert("获取搭配组数据出错！");
		},
		
	});
}
// 表单提交验证
function checkForm() {
	var foodCreditCount = 0;
	$('.fooditem').each(function(){
		var isChs = $(this).find(".foodischs").val();
		
		var foodCheckStatus = $(this).find('.cbmitem-input').is(':checked');
		if(foodCheckStatus == true) {
			var foodCredit = parseFloat($(this).find(".foodcredit").val());
			var foodCount = $(this).find(".foodcount").val();
			
			foodCreditCount += parseInt((foodCredit * foodCount));
		} 
	});
	if(foodCreditCount > foodCreditTotal) {
		alert('您当前的选择超出了套餐允许的分值, 请重新选择提交!');
		return false;
	}
	
	
	$('.fooditem').each(function(){
		var isChs = $(this).find(".foodischs").val();
	});
	
	return true;
}
$(document).ready(function(){
	$('.cbmitem-input').each(function(){
		var isChs = $(this).parent().next().val();
		if(isChs == 1) {
			$(this).attr('checked', 'true');
		}
	
		$(this).change(function(){
			var foodCheckStatus = $(this).is(':checked');
			if(foodCheckStatus == true) {
				$(this).parent().next().val(1);
			} else {
				$(this).parent().next().val(0);
			}
		});
	});
});
</script>
